package com.itheima.service.impl;
/*
    ヾ(❀ﾟ▽ﾟ)ノ 
 
 Grey1996year@163.com 
 
*/

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.mapper.PermissionMapper;
import com.itheima.pojo.Permission;
import com.itheima.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

@Service(interfaceClass = PermissionService.class)
@Transactional
public class PermissionServiceImpl implements PermissionService {

	@Autowired
	private PermissionMapper permissionMapper;

	@Override
	public void add(Permission permission) {
		permissionMapper.add(permission);
	}

	@Override
	public PageResult findAll(QueryPageBean queryPageBean) {
		//
		Integer currentPage = queryPageBean.getCurrentPage();
		Integer pageSize = queryPageBean.getPageSize();
		String queryString = queryPageBean.getQueryString();
		PageHelper.startPage(currentPage,pageSize);
		//
		Page<Permission> page = permissionMapper.queryByCondition(queryString);


		return new PageResult(page.getTotal(),page.getResult());
	}

	@Override
	public void delete(Integer id) {
		//1 删除与role的中间表
		permissionMapper.deleteRelation(id);
		//2 删除permission表
		permissionMapper.delete(id);


	}

	@Override
	public Permission findById(Integer id) {
		Permission permission = permissionMapper.findById(id);

		return permission;
	}

	@Override
	public void update(Permission permission) {
		permissionMapper.update(permission);


	}
}
